package com.ofek.applicationbase.forms;

import com.ofek.applicationbase.broadcast.Delegate;

public class QuestionViewController {
	protected QuestionView question;

	public QuestionViewController(final QuestionView view) {
		question = view;
		question.registerAnswerChangedListener(new Delegate<Object>() {

			@Override
			public void invoke(final Object t) {
				onAnswerChanged(t);
			}
		});
	}

	protected void onAnswerChanged(final Object t) {}

	public boolean onSubmitRequested(final boolean shouldAnimateIfInvalid) {
		final boolean valid = question.hasValidInput();
		if (!valid && shouldAnimateIfInvalid) question.animateInvalidInput();
		return valid;
	}


	public QuestionView getQuestion() {
		return question;
	}

	public void setRequired(final boolean required) {
		question.setRequired(required);
	}

	public boolean isRequired() {
		return question.isRequired();
	}

	public void setDefaultAnswer(final Object answer) {
		question.setAnswer(answer);
	}


}
